// 创建 Toast 容器
function createToastContainer() {
    let container = document.getElementById('toast-container');
    if (!container) {
        container = document.createElement('div');
        container.id = 'toast-container';
        container.className = 'layui-fixbar';
        container.style.position = 'fixed';
        container.style.top = '20px';
        container.style.right = '20px';
        container.style.zIndex = '1080';
        container.style.padding = '10px';
        document.body.appendChild(container);
    }
    return container;
}

// 显示 Toast 提示
function showToast(message, type = 'info') {
    const container = createToastContainer();
    const toast = document.createElement('div');
    
    // 设置 Toast 类型对应的颜色
    const typeClass = {
        'success': 'layui-bg-green',
        'error': 'layui-bg-red',
        'warning': 'layui-bg-orange',
        'info': 'layui-bg-blue'
    }[type] || 'layui-bg-blue';
    
    // 设置 layui 样式
    toast.className = `layui-elem-quote ${typeClass} text-white`;
    toast.style.marginBottom = '10px';
    toast.style.padding = '15px';
    toast.style.borderRadius = '4px';
    toast.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
    toast.style.position = 'relative';
    
    // 添加内容和关闭按钮
    toast.innerHTML = `
        <div style="padding-right: 30px;">
            ${message}
        </div>
        <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" style="position: absolute; top: 5px; right: 5px; line-height: 1; padding: 4px 8px;">
            ×
        </button>
    `;
    
    // 添加到容器
    container.appendChild(toast);
    
    // 点击关闭按钮隐藏
    const closeBtn = toast.querySelector('button');
    closeBtn.onclick = function() {
        toast.style.opacity = '0';
        toast.style.transition = 'opacity 0.3s';
        setTimeout(() => {
            toast.remove();
        }, 300);
    };
    
    // 自动隐藏
    setTimeout(() => {
        toast.style.opacity = '0';
        toast.style.transition = 'opacity 0.3s';
        setTimeout(() => {
            toast.remove();
        }, 300);
    }, 3000);
}
